package com.zhangxi.mapper;

import com.github.pagehelper.Page;
import com.zhangxi.annotation.AutoFill;
import com.zhangxi.dto.SetMealPageQueryDTO;
import com.zhangxi.entity.Dish;
import com.zhangxi.entity.SetMeal;
import com.zhangxi.enumeration.OperationType;
import com.zhangxi.result.PageResult;
import com.zhangxi.vo.DishItemVO;
import com.zhangxi.vo.SetMealVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * ClassName: SetMealMapper
 * Package: com.zhangxi.mapper
 */
@Mapper
public interface SetMealMapper {

    /**
     * 分页查询套餐
     *
     * @param setMealPageQueryDTO
     * @return
     */
    Page<SetMealVo> page(SetMealPageQueryDTO setMealPageQueryDTO);

    /**
     * 新增操作
     *
     * @param setMeal
     */
    @AutoFill(OperationType.INSERT)
    void insert(SetMeal setMeal);

    /**
     * 根据id查询出套餐信息
     * @param id
     * @return
     */
    @Select("select * from setmeal where id = #{id}")
    SetMeal getById(Long id);

    /**
     * 更新套餐
     * @param setMeal
     */
    @AutoFill(OperationType.UPDATE) //公共属性的自动赋值
    void update(SetMeal setMeal);

    /**
     * 删除套餐表中数据
     * @param ids
     */
    void delete(List<Long> ids);

    /**
     * 条件查询SetMeal
     * @param setMeal
     * @return
     */
    List<SetMeal> list(SetMeal setMeal);


    /**
     * 根据套餐id查询菜品选项
     * @param setmealId
     * @return
     */
    @Select("select sd.name, sd.copies, d.image, d.description " +
            "from setmeal_dish sd left join dish d on sd.dish_id = d.id " +
            "where sd.setmeal_id = #{setmealId}")
    List<DishItemVO> getDishItemBySetmealId(Long setmealId);

    /**
     * 根据条件统计套餐数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
